package com.test.service;

import com.test.mapper.UserMapper;
import com.test.model.User;
import io.shardingsphere.core.api.HintManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public User getUserByUserId(Integer userId) {
        User user = userMapper.getUserByUserId(userId);
        return user;
    }

    public List<User> getUsers() {
        return userMapper.getUsers();
    }

    public User getUserByUserIdFromMaster(Integer userId) {
        try (HintManager hintManager = HintManager.getInstance();) {
            hintManager.setMasterRouteOnly();
            return userMapper.getUserByUserId(userId);
        } catch (Exception e) {
            throw e;
        }
    }

    public void createUser(User user) {
        userMapper.createUser(user);
    }

}
